{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "from common import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "RESULT_JSON = \"/Users/law/repos/viper/results/access_pattern/all_access_pattern.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "results_raw = json.loads(open(RESULT_JSON).read())\n",
    "assert results_raw[\"context\"][\"library_build_type\"] != \"debug\"\n",
    "\n",
    "BENCHMARKS =  results_raw[\"benchmarks\"]\n",
    "# print(BENCHMARKS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "runs = defaultdict(list)\n",
    "\n",
    "DIMM = 'dimm'\n",
    "BLOCK = 'block'\n",
    "\n",
    "for bm in BENCHMARKS:\n",
    "    if DIMM in bm['name']:\n",
    "        runs[DIMM].append(bm)\n",
    "    elif BLOCK in bm['name']:\n",
    "        runs[BLOCK].append(bm)\n",
    "    else:\n",
    "        raise RuntimeError(f\"Unknown benchmark type {bm['name']}\")\n",
    "\n",
    "runs[DIMM].sort(key=lambda x: x['threads'])\n",
    "runs[BLOCK].sort(key=lambda x: x['threads'])\n",
    "\n",
    "pprint(runs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dimm_runs = [run['items_per_second'] / MILLION for run in runs[DIMM]]\n",
    "block_runs = [run['items_per_second'] / MILLION for run in runs[BLOCK]]\n",
    "\n",
    "fig, ax = plt.subplots(1, 1, figsize=(4, 3))\n",
    "\n",
    "num_threads = list(range(1, 37, ))\n",
    "ax.plot(num_threads, dimm_runs, label=\"DIMM\", ls='-.', color=COLORS[3])\n",
    "ax.plot(num_threads, block_runs, label=\"VBlock\", ls='-', color=COLORS[0])\n",
    "ax.set_yticks(range(1, 12))\n",
    "ax.yaxis.set_major_locator(MultipleLocator(2))\n",
    "\n",
    "ax.set_ylabel(\"Throughput (Mops/s)\", fontsize=18)\n",
    "ax.set_xlabel(\"# Threads\", fontsize=18)\n",
    "ax.legend(frameon=True, loc='upper left', fontsize=18,\n",
    "          columnspacing=1.3, handletextpad=0.3, labelspacing=0.1,\n",
    "         bbox_to_anchor=(-0.03, 1.13))\n",
    "\n",
    "for tick in ax.xaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(18)\n",
    "for tick in ax.yaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(18)\n",
    "\n",
    "ax.yaxis.set_label_coords(-0.12, 0.45)\n",
    "\n",
    "ax.set_axisbelow(True)\n",
    "ax.grid(axis='y', which='major')\n",
    "fig.savefig('charts/access_pattern.pdf', bbox_inches='tight')\n",
    "fig.savefig('charts/access_pattern.svg', bbox_inches='tight')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
